﻿using MediatR;
using Production_Get.API.Infrastructures.Interfaces;
using Return.Enum;
using THE_WIND_RISES.Common.Domans.Produce.DemandPlanning;
using THE_WIND_RISES.Common.Domans.Produce.ManifestInfos;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Get.API.Application.MaterialManagement.Row
{
    public class RowMaterialPlanningSeachHandler : IRequestHandler<RowMaterialPlanningSeachCommon, Result>
    {
        private readonly IBaseRepositoryGet<MaterialPlanningRow> MaterialPlanningRowRepository;
        public RowMaterialPlanningSeachHandler(IBaseRepositoryGet<MaterialPlanningRow> materialPlanningRowRepository)
        {
            MaterialPlanningRowRepository = materialPlanningRowRepository;
        }

        public async Task<Result> Handle(RowMaterialPlanningSeachCommon request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCodes.Search };
            string sql = "SELECT * FROM MaterialPlanningRow a INNER JOIN Choose c on a.ChooseId=c.ChooseId JOIN AttributeRow d on a.AttributeRowId=d.AttributeRowId";
            var list = MaterialPlanningRowRepository.GetAll(sql).ToList();
            if (list != null)
            {
                result.Code = (int)CommonErrorCodes.Success;
                result.Data = list;
                result.Msg = "显示成功";
            }
            else
            {
                result.Msg = "显示失败";
            }
            return result;
        }
    }
}
